import query from '@dfeidao/atom-nodejs/db/query';
import log from '@dfeidao/atom-nodejs/logger/log';

interface Message {
	productid: string;
	role_no: string;
}

interface Data {
	pk_val: string;
	no: string;
}
export default async function atom(msg: Message, action_id: string, session_id: string) {
	log(`Service begin`);
	// todo
	const systemid = '12';
	const productid = msg.productid;
	const role_no = msg.role_no;
	const { exec, prepare } = query(action_id, session_id, systemid);
	prepare('pub_role_allot', ['pk_val', 'search_field_val'], { productid, role_no }, 199, 1,[],[]);
	const [data] = await exec<Data>();
	const arr = data.map((v) => {
		return v.pk_val;
	});
	prepare('auth_formgroup', ['no', 'name'], { productid }, 199, 1,[],[]);
	const [data1] = await exec<Data>();
	const data2 = data1.filter((v) => {
		return arr.indexOf(v.no) === -1;
	});
	log(`Service end`);
	return data2;

}

